package com.lagou.sqlSession;

import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * 解析xml,封装Configuration
 */
public class SqlSessionFactoryBuilder {




    /**
     * 生产SqlSessionFactory
     */
    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException, ClassNotFoundException {
        //使用dom4j解析配置文件，讲配置加载到Configration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);


        //创建SqlSessionFactory的实现类DefaultSqlSession
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }

}
